#ifndef PDO_MAP_H
#define PDO_MAP_H
#include "slave_info.h"

/************************* AC1181 PDO/Sync 配置 *************************/
static ec_pdo_entry_info_t ac1181_pdo_entries[] = {
    {0x7000, 0x01, 1},
    {0x7010, 0x01, 1},
    {0x7020, 0x01, 1},
    {0x7030, 0x01, 1},
    {0x7040, 0x01, 1},
    {0x7050, 0x01, 1},
    {0x7060, 0x01, 1},
    {0x7070, 0x01, 1},
    {0x6000, 0x01, 1},
    {0x6010, 0x01, 1},
    {0x6020, 0x01, 1},
    {0x6030, 0x01, 1},
    {0x6040, 0x01, 1},
    {0x6050, 0x01, 1},
    {0x6060, 0x01, 1},
    {0x6070, 0x01, 1},
};
static ec_pdo_info_t ac1181_pdos[] = {
    {0x1600, 8, ac1181_pdo_entries},     // Outputs
    {0x1a00, 8, ac1181_pdo_entries + 8}, // Inputs
};

ec_sync_info_t slave_ac1181_syncs[] = {
    {0, EC_DIR_OUTPUT, 1, ac1181_pdos, EC_WD_ENABLE},
    {1, EC_DIR_INPUT, 1, ac1181_pdos + 1, EC_WD_DISABLE},
    {0xff}};

static ec_pdo_entry_info_t al3608_pdo_entries[] = {
    {0x7000, 0x01, 16},
     {0x7010, 0x01, 16}, 
     {0x7020, 0x01, 16}, 
     {0x7030, 0x01, 16}, 
     {0x7040, 0x01, 16},
      {0x7050, 0x01, 16},
       {0x7060, 0x01, 16}, 
       {0x7070, 0x01, 16},
    // Channel 1
    {0x6000, 0x01, 1},
    {0x6000, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6000, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6000, 0x0f, 1},
    {0x6000, 0x10, 1},
    {0x6000, 0x11, 16},
    // Channel 2
    {0x6010, 0x01, 1},
    {0x6010, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6010, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6010, 0x0f, 1},
    {0x6010, 0x10, 1},
    {0x6010, 0x11, 16},
    // Channel 3
    {0x6020, 0x01, 1},
    {0x6020, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6020, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6020, 0x0f, 1},
    {0x6020, 0x10, 1},
    {0x6020, 0x11, 16},
    // Channel 4
    {0x6030, 0x01, 1},
    {0x6030, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6030, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6030, 0x0f, 1},
    {0x6030, 0x10, 1},
    {0x6030, 0x11, 16},
    // Channel 5
    {0x6040, 0x01, 1},
    {0x6040, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6040, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6040, 0x0f, 1},
    {0x6040, 0x10, 1},
    {0x6040, 0x11, 16},
    // Channel 6
    {0x6050, 0x01, 1},
    {0x6050, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6050, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6050, 0x0f, 1},
    {0x6050, 0x10, 1},
    {0x6050, 0x11, 16},
    // Channel 7
    {0x6060, 0x01, 1},
    {0x6060, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6060, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6060, 0x0f, 1},
    {0x6060, 0x10, 1},
    {0x6060, 0x11, 16},
    // Channel 8
    {0x6070, 0x01, 1},
    {0x6070, 0x02, 1},
    {0x0000, 0x00, 4},
    {0x6070, 0x07, 1},
    {0x0000, 0x00, 7},
    {0x6070, 0x0f, 1},
    {0x6070, 0x10, 1},
    {0x6070, 0x11, 16},
    {0x0000, 0x00, 16}, // Gap
};
static ec_pdo_info_t al3608_pdos[] = {
    {0x1a00, 73, al3608_pdo_entries}, // Inputs，数量为73
};

ec_sync_info_t slave_ac3608_syncs[] = {
    {0, EC_DIR_INPUT, 1, al3608_pdos, EC_WD_DISABLE},
    {0xff}};

ec_dc_info_t slave_ac3608_dc = {
    .is_supoort_dc = false;
};
ec_dc_info_t  slave_ac1181_dc = {
    .is_supoort_dc = false;
};

ec_data_info_t slave_ac3608_data [] = {
    // 0x6000 01
    {
       .data_type =  BOOL_TYPE
    },
     // 0x7000 01
    {
       .data_type =  BOOL_TYPE
    }
}

ec_data_info_t slave_ac1181_data [] = {
    // 0x6000 01
    {
       .data_type =  BOOL_TYPE
    },
     // 0x7000 01
    {
       .data_type =  BOOL_TYPE
    }
}

#define SLAVE_NUMS 2
slave_info_t slave_info[SLAVE_NUMS] = {
    // ac3608
    {
        .alias = 0,
        .postion = 0,
        .vendor_id = 0x000002ea,
        .product_code = 0xc0041181,
        .slave_sync_info = &slave_ac3608_syncs,
        .slave_dc_info = slave_ac3608_dc,
        .slave_data_info = slave_ac3608_data
    },
    // ac1181
    {
        .alias = 0,
        .postion = 0,
        .vendor_id = 0x000002ea,
        .product_code = 0xc0043608,
        .slave_sync_info = &slave_ac1181_syncs,
        .slave_dc_info = slave_ac1181_dc,
        .slave_data_info = slave_ac1181_data
    }
};


const static ec_pdo_entry_reg_t domain_regs[] = {
    // AC1181 8路输入
    {slave_info[1].vendor_id, slave_info[1].product_code, 0x6000, 0x01, &slave_ac1181_data[0].data_byte_offset, &slave_ac1181_data[0].data_bit_offset},
    // AC1181 8路输出
    {slave_info[1].vendor_id, slave_info[1].product_code, 0x7000, 0x01,  &slave_ac1181_data[1].data_byte_offset, &slave_ac1181_data[1].data_bit_offset},
    // AL3608 8路16位模拟量输入
    // CJCompensation 1~8
    {slave_info[0].vendor_id, slave_info[0].product_code, 0x7000, 0x01,  &slave_ac3608_data[0].data_byte_offset, &slave_ac3608_data[0].data_bit_offset},
    // Channel 1
    {slave_info[0].vendor_id, slave_info[0].product_code, 0x6000, 0x01,  &slave_ac3608_data[1].data_byte_offset, &slave_ac3608_data[1].data_bit_offset},
    {}};



master_info_t master_info [] = {
    {
        .period_ns = 1000000
    }
};


global_config_info_t global_config_info ={
    .slave_infos = slave_info,
    .slave_count = SLAVE_NUMS,
    .domain_regs = domain_regs,
    .master_info = master_info,
    .master_count = 1
},
#endif // PDO_MAP_H